//
//  MCActionViewModel.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/23.
//

import Foundation
import Moya

enum MCActionViewModel {
    //获取所有的部位
    case getExercisePosition
    //获取器械的部分内容
    case getInstrumentPageList(current:Int)
    //获取动作的部分内容
    case getActionPageListApp(current:Int,postition:String)
}

extension MCActionViewModel:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .getExercisePosition:
            return "api/admin/dict/exercisePosition"
        case .getInstrumentPageList:
            return "api/app/action/getInstrumentPageForApp"
        case .getActionPageListApp:
            return "api/app/action/getActionPageForApp"
        }
    }
    var method:Moya.Method {
        switch self {
        case .getExercisePosition:
            return .get
        case .getInstrumentPageList:
            return .get
        case .getActionPageListApp:
            return .get
            
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case .getExercisePosition:
            return .requestPlain
        case let .getInstrumentPageList(current):
            return .requestParameters(parameters: ["current":current,"size":20], encoding: URLEncoding.default)
        case let .getActionPageListApp(current, postition):
            var param:Dictionary<String,Any> = ["current":current,"size":20]
            if postition.isEmpty == false {
              param["position"] = postition
            }
            
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
        
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
    
}

